#include <iostream>
#include <string>
#include <stack>
using namespace std;

class Solution 
{
public:
    bool isValid(string s) 
	{
        // Start typing your C/C++ solution below
        // DO NOT write int main() function

		stack<char> ss;
		for(size_t i=0;i<s.size();i++)
		{
			if((s[i]=='(') || (s[i]=='{') || (s[i]=='['))
				ss.push(s[i]);
			else if(ss.empty())
				return false;
			else
			{
				char target;
				switch(s[i])
				{
				case ')':
					target = '(';
					break;
				case '}':
					target = '{';
					break;
				case ']':
					target = '[';
					break;
				default:
					return false;
				}

				if(ss.top() == target)
					ss.pop();
				else
					return false;
			}
		}

		return ss.empty();
    }
};

int main()
{
	string line;
	Solution s;
	while(getline(cin,line))
	{
		if(line=="")
			break;
		cout<<s.isValid(line)<<endl;
	}
}